import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class ClientMain {
    public static void main(String[] args) {
        int port = Global.port;
        try (
                Socket socket = new Socket("127.0.0.1", port);
                PrintWriter writer = new PrintWriter(socket.getOutputStream(), true);
                BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        ) {
//            writer.write("query time order."); // block cause no line_end_sep
            writer.println("query time order.");
//            writer.println("mock err order.");
            String resp = reader.readLine();
            System.out.println(resp);

            for (String line = input.readLine();
                 Global.whileFlag && line != null && !line.trim().equals("");
                 line = input.readLine()) {
                writer.println(line);
                resp = reader.readLine();
                if (resp == null) {
                    System.out.println("link to server closed before");
                    break;
                } else {
                    System.out.println("recv from server:" + resp);
                }
            }
            System.out.println("client exit");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
